/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax.card;

import deatax.GameData;
import deatax.Player;
import deatax.Resource;
import java.util.ArrayList;

/**
 * This card gives the current player a percentage of their current amount of a given 
 * resource (e.g. if arg[0] is Money and arg[1] is 10, then 10% of the current player's money
 * is given)
 * @author pson
 */
public class CardResourcePercent extends CardEffect {

    @Override
    public void run(GameData data, String[] args) {
        ArrayList<Player> players = new ArrayList<Player>();
        if (args[0].equals("All")) {
            players.addAll(data.getRoster().getPlayers());
        } else if (args[0].equals("Self")) {
            players.add(data.getCurrentPlayer());
        } else if (args[0].equals("Other")) {
            players.addAll(data.getRoster().getPlayers());
            players.remove(data.getCurrentPlayer());
        }

        Resource r = data.getGame().getResource(args[1]);
        int pc = Integer.parseInt(args[2]);
        for (Player p : players) {

            int cn = p.getResourceNum(r);
            if (cn > 0) {
                int bonus = (cn * pc) / 100;
                int after = p.addResource(r, bonus);
                if (pc > 0) {
                    data.getGui().addMessage(p, "Receives a " + pc + "% bonus to " + r.getName() + " (" + cn + " > " + after + ")");
                } else {
                    data.getGui().addMessage(p, "Loses " + (-pc) + "% of their " + r.getName() + " (" + cn + " > " + after + ")");
                }
            }
        }
    }
}
